﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Utils;
namespace UI.ModSalesman
{
    public partial class SalesmanList : System.Web.UI.Page
    {
        SalesmanBiz salesmanBiz = new SalesmanBiz();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                btnAdd.Attributes.Add("onclick", "javascript:ShowLink('SalesmanAdd.aspx',800,550);");
            }
        }
        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string timeType = ddlTimeType.SelectedValue;
            string stateName = ddlStateName.SelectedItem.Text.Trim();
            if (stateName==""&&string.IsNullOrEmpty(serWord) && string.IsNullOrEmpty(bTime))
            {
                bTime = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd");
                txtBtime.Text = bTime;
                txtEtime.Text = System.DateTime.Now.ToString("yyyy-MM-dd");
            }

            DataTable dt = salesmanBiz.GetLists(serWord, bTime, eTime, stateName, timeType);
            gvList.DataSource = dt;
            gvList.DataBind();
            lbAmount.Text = dt.Rows.Count.ToString();
        }




        protected void btnExcel_Click(object sender, EventArgs e)
        {
            // ExcelUtility.GridViewToExcel(gvList, "Sales.xls");
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string timeType = ddlTimeType.SelectedValue;
            string stateName = ddlStateName.SelectedItem.Text.Trim();

            ExcelUtility.ExportDsToXls(this, salesmanBiz.GetLists(serWord, bTime, eTime, stateName, timeType), "Sales.xls");

        }


        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F3F8F8'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            }
        }
    }
}